/**
 * 0394
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-10-27 下午4:22
 */

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

class Solution {
public:
    string decodeString(string s) {
        stack<int> intSt;
        stack<string> strSt;

        strSt.push("");
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] >= 'a' && s[i] <= 'z') {
                string tmp = strSt.top();
                strSt.pop();
                tmp += s[i];
                strSt.push(tmp);
            } else if (s[i] >= '0' && s[i] <= '9') {
                int k = 0;
                while (s[i] != '[') {
                    k = k * 10 + s[i] - '0';
                    i++;
                }
                intSt.push(k);
                strSt.push("");
            } else {
                int k = intSt.top();
                string tmp = strSt.top();
                intSt.pop();
                strSt.pop();
                string res;
                for (int j = 0; j < k; ++j) {
                    res += tmp;
                }
                tmp = strSt.top();
                strSt.pop();
                tmp += res;
                strSt.push(tmp);
            }
        }

        return strSt.top();
    }
};

int main() {

    return 0;
}